home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4603 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: logica.co.uk!apple
  2. From: jjk@lbvrtda.logica.com (Jan Just [JJ] Keijser)
  3. Newsgroups: comp.lang.c,comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Re: Device Drivers
  5. Date: Wed, 31 Jan 96 08:56:01 GMT
  6. Organization: Logica BV
  7. Message-ID: <4enaqh$497@romeo.logica.co.uk>
  8. References: <4em26p$el1@canopus.cc.umanitoba.ca>
  9. NNTP-Posting-Host: 158.234.122.115
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4em26p$el1@canopus.cc.umanitoba.ca>,
  13.    natewild@mbnet.mb.ca (Nathan T. Wild) wrote:
  14. >I would like to be able to make device drivers in C. I writing an
  15. >application which uses loadable modules for some of it's functions.  
  16. >Currently these functions are written in Assembly language.  The
  17. >assembled executable code is stripped of it's EXE header and the
  18. >contents is written directly to memory...  Then a function pointer is
  19. >set to point to this code.
  20. >This works...  But how can I go about generating these executable
  21. >"driver" files in C, rather than assembly language?  In order to link my
  22. >C code, I need a main()?
  23. What you can do is create an executable that you can also load as a device 
  24. driver. This is only possible if your C compiler does not reorder the 
  25. datasegment, i.e. if the first global variable you define is put at the start 
  26. of the EXE file (Turbo C and Borlannd C++ work). The trick is to create a 
  27. device driver header as the first global variable and set up the strategy and 
  28. interrupt routines. You have to do a stack switch probably, as C programs 
  29. usually are quite heavy on the stack. The device driver can be called by any 
  30. program with a stack of e.g. 256 bytes, which might not be enough.
  31.  
  32. The main() function can then simply say
  33.   "Load me as a device driver:
  34.         DEVICE=C:\BARF\DO_BARF.EXE
  35.   "
  36. or something like that. I've used this trick for Turbo Pascal 6 and Turbo C 
  37. 2.0 and higher and it works fine. The speed of the device driver is not all 
  38. that good though, assembly is much faster then any C compiler I've gotten my 
  39. hands on so far (including Borland C++ 4.5 and MS C++ 8)
  40.  
  41. HTH,
  42.  
  43. JJ
  44.  
  45.  
  46. ----------------------------------------------------------
  47.   Jan Just (JJ) Keijser
  48.   SMTP: jjk@lbvrtda.logica.com
  49.   X400: C=GB A=ATTMAIL P=Logica O=LBV OU1=LBVRTDA S=JJK
  50.   I prefer clear blue skies over a bunch of clouds any day
  51.   My views are my own...
  52. ----------------------------------------------------------
  53.